﻿using System;
using UnityEngine;
using System.Collections.Generic;

/// <summary>
/// 动作枚举
/// </summary>
public enum AnimationType{
	none = 0,
	shouji = 1,
	daiji = 2,
	paobu = 3,
	skill1 = 4,
	skill2 = 5,
	skill3 = 6,
}

/// <summary>
/// 动作名称管理
/// </summary>
public class AnimationName
{
	/// <summary>
	/// 一个animationtype对应多个animationName 目前测试资源动作名不统一
	/// </summary>
	private static Dictionary<int,List<string>> _animationDic;
	private static void InitAnimationDic(){
		_animationDic = new Dictionary<int, List<string>> ();
		_animationDic.Add ((int)AnimationType.daiji,new List<string>(){"idle","Idle","dm_daiji_zhandou"});
		_animationDic.Add ((int)AnimationType.shouji,new List<string>(){"hit","Magic","dm_shouji"});
		_animationDic.Add ((int)AnimationType.paobu,new List<string>(){"run","Run","dm_paobu"});
		_animationDic.Add ((int)AnimationType.skill1,new List<string>(){"attack1","Attack1","dm_skill01"});
		_animationDic.Add ((int)AnimationType.skill2,new List<string>(){"attack2","Attack2","dm_skill01"});
		_animationDic.Add ((int)AnimationType.skill3,new List<string>(){"attack3","Attack3","dm_skill01"});
	}
	private static Dictionary<int,List<string>> animationDic
	{
		get{
			if (_animationDic == null)
				InitAnimationDic ();
			return _animationDic;
		}
	}

	/// <summary>
	/// 动作是否循环或一次
	/// </summary>
	private static Dictionary<int,WrapMode> _wrapDic;
	private static void InitWrap(){
		_wrapDic = new Dictionary<int, WrapMode> ();
		_wrapDic.Add ((int)AnimationType.shouji,WrapMode.Once);
		_wrapDic.Add ((int)AnimationType.daiji,WrapMode.Loop);
		_wrapDic.Add ((int)AnimationType.paobu,WrapMode.Loop);
		_wrapDic.Add ((int)AnimationType.skill1,WrapMode.Once);
		_wrapDic.Add ((int)AnimationType.skill2,WrapMode.Once);
		_wrapDic.Add ((int)AnimationType.skill1,WrapMode.Once);
	}

	private static Dictionary<int,WrapMode> wrapDic
	{
		get{ 
			if (_wrapDic == null)
				InitWrap ();
			return _wrapDic;
		}
	}

	/// <summary>
	/// 根据animationType获取animationName;
	/// </summary>
	/// <returns>The animation name.</returns>
	/// <param name="ani">Ani.</param>
	/// <param name="animation">Animation.</param>
	public static string GetAnimationName(AnimationType ani,Animation animation){
		if (animationDic == null)
			InitAnimationDic ();
		if (animationDic.ContainsKey ((int)ani)) {
			List<string> nameList = animationDic [(int)ani];
			foreach (string name in nameList) {
				if (animation.GetClip (name) != null)
					return name;
			}
		}
		return "";
	}

	/// <summary>
	/// 根据动作名获取枚举
	/// </summary>
	/// <returns>The animation type.</returns>
	/// <param name="animationName">Animation name.</param>
	public static AnimationType GetAnimationType(string animationName){
		foreach (var val in animationDic) {
			foreach (string name in val.Value) {
				if (name == animationName)
					return (AnimationType)val.Key;
			}
		}
		return AnimationType.daiji;
	}

	/// <summary>
	/// 获取动作播放模式
	/// </summary>
	/// <returns>The animation wrap.</returns>
	/// <param name="animationName">Animation name.</param>
	public static WrapMode GetAnimationWrap(string animationName){
		AnimationType animationType = GetAnimationType (animationName);
		if (wrapDic.ContainsKey((int)animationType)) {
			return wrapDic [(int)animationType];
		}
		return WrapMode.Once;
	}

}